/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('nbf', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AddRequest {
  x?: int32(name='x'),
  y?: int32(name='y'),
}

model AddResponseBody = {
  sum?: int32(name='sum'),
}

model AddResponse = {
  headers: map[string]string(name='headers'),
  body: AddResponseBody(name='body'),
}

async function add(request: AddRequest): AddResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return addWithOptions(request, headers, runtime);
}

async function addWithOptions(request: AddRequest, headers: map[string]string, runtime: Util.RuntimeOptions): AddResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.x)) {
    query['x'] = request.x;
  }
  if (!Util.isUnset(request.y)) {
    query['y'] = request.y;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'Add',
    version = '2021-09-16_15-19-21-459',
    protocol = 'HTTPS',
    pathname = `/caiheRoaProduct/10_0_0/add`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model CaiheAutoApi1Request {
  f0?: int32(name='f0', description='param0'),
  f1?: int32(name='f1', description='param1'),
}

model CaiheAutoApi1ResponseBody = {
  sum?: int32(name='Sum', description='sum'),
}

model CaiheAutoApi1Response = {
  headers: map[string]string(name='headers'),
  body: CaiheAutoApi1ResponseBody(name='body'),
}

async function caiheAutoApi1(request: CaiheAutoApi1Request): CaiheAutoApi1Response {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return caiheAutoApi1WithOptions(request, headers, runtime);
}

async function caiheAutoApi1WithOptions(request: CaiheAutoApi1Request, headers: map[string]string, runtime: Util.RuntimeOptions): CaiheAutoApi1Response {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.f0)) {
    query['f0'] = request.f0;
  }
  if (!Util.isUnset(request.f1)) {
    query['f1'] = request.f1;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CaiheAutoApi1',
    version = '2021-09-16_15-19-21-459',
    protocol = 'HTTPS',
    pathname = `/caihe/auto1`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

